package com.yiba.vpn.config;

import com.yiba.vpn.authorization.interceptor.AuthorizationInterceptor;
import com.yiba.vpn.authorization.resolvers.CurrentUserMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * 配置类，增加自定义拦截器和解析器
 * @see CurrentUserMethodArgumentResolver
 * @see AuthorizationInterceptor
 * @author ScienJus
 * @date 2015/7/30.
 */
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private AuthorizationInterceptor authorizationInterceptor;

    @Autowired
    private CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration ir = registry.addInterceptor(authorizationInterceptor);
        ir.excludePathPatterns("/i/do");
        ir.excludePathPatterns("/user/do");
        ir.excludePathPatterns("/user/invite");
        
        ir.excludePathPatterns("/serve/showAppServe");
        ir.excludePathPatterns("/serve/showAppServeLanguage");
        ir.excludePathPatterns("/user/login");
        ir.excludePathPatterns("/user/oauthLogin");
        ir.excludePathPatterns("/tokens");
        ir.excludePathPatterns("/tokens/refreshToken");
        ir.excludePathPatterns("/vpn/add");
        ir.excludePathPatterns("/monitorvpn/hostrestart");
        ir.excludePathPatterns("/weixin/wxNotify");
        ir.excludePathPatterns("/pay/alipayNotify");
        ir.excludePathPatterns("/error");
        ir.excludePathPatterns("/weixin/wxLogin");
        ir.excludePathPatterns("/weixin/wxRefreshToken");
        ir.excludePathPatterns("/vpnProxyDomain/batchAdd");
        ir.excludePathPatterns("/vpnProxyDomain/delProxyDomain");
        ir.excludePathPatterns("/vpnProxyDomain/findAll");
        ir.excludePathPatterns("/user/initData");
        ir.excludePathPatterns("/push/taskPush");
        ir.excludePathPatterns("/weixin/wxScanNotify");

        ir.excludePathPatterns("/monitorvpn/hostrestart");
        ir.excludePathPatterns("/monitorvpn/addserver");
        ir.excludePathPatterns("/monitorvpn/hostdel");
        ir.excludePathPatterns("/monitorvpn/hostupdate");
        ir.excludePathPatterns("/monitorvpn/overload");
        ir.excludePathPatterns("/monitorvpn/nflow");


        ir.excludePathPatterns("/user/getvcode");
        ir.excludePathPatterns("/user/registerAjax");
        ir.excludePathPatterns("/user/register");
        ir.excludePathPatterns("/user/activate");

        ir.excludePathPatterns("/user/lgin");
        ir.excludePathPatterns("/user/forgetpwd");
        ir.excludePathPatterns("/user/register");
        ir.excludePathPatterns("/user/repwd");
        ir.excludePathPatterns("/user/loginweb");
        ir.excludePathPatterns("/user/sendemail");

        ir.excludePathPatterns("/user/vecode");
        ir.excludePathPatterns("/user/upwd");
        ir.excludePathPatterns("/user/fresetpwd");
        //web 访问记录
        ir.excludePathPatterns("/monitor/vist");
        
        ir.excludePathPatterns("/testHelp/updateFlag");
        ir.excludePathPatterns("/testHelp/cleanTestData");
        ir.excludePathPatterns("/testHelp/repairTestData");
        ir.excludePathPatterns("/testHelp/updateTestSetMealTime");
        ir.excludePathPatterns("/testHelp/repairTestSetMealTime");

        // 我的页面
        ir.excludePathPatterns("/my");

        // 空投页面
        ir.excludePathPatterns("/wfeeairdrop");
        
        ir.excludePathPatterns("/router/sum");
        ir.excludePathPatterns("/router/getcode");
        ir.excludePathPatterns("/router/subscribe");
        ir.excludePathPatterns("/router/getuserinfo");
        ir.excludePathPatterns("/router/savewallet");
        ir.excludePathPatterns("/router/updaterandom");
        ir.excludePathPatterns("/router/robot");


        super.addInterceptors(registry);
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(currentUserMethodArgumentResolver);
    }
}
